;{

const body = $(document.body);
const max = $('section').length - 1;
const dur = 500;
let fitValve = true;
let mouseValve = true;

let getIndex = () => {
	let i = parseInt(location.hash.split('#')[1]) || 0;
	if (i < 0 ) i = 0;
	if (i > max ) i = max;
	return i;
};
let turn = i => {
	let marginTop = - body.height() * i;
	$('section').eq(0).animate({ marginTop }, dur);
	
	let a = $('nav').children('a');
	a.filter('.checked').removeClass('checked');
	a.eq(i).addClass('checked');
};
let fit = () => {
	if (!fitValve) return;
	fitValve = false;
	setTimeout(() => (fitValve = true), dur);

	let height = body.height();
	$('section').css({ height });
	turn(getIndex());
};
fit();


let next = () => {
	var i = getIndex();
	if (i >= max) return;
	location.hash = i + 1;
};
let prev = () => {
	let i = getIndex();
	if (i <= 0) return;
	location.hash = i - 1;
};
window.onhashchange = () => turn(getIndex());
window.onresize = fit;
window.onmousewheel = e => {
	if(!mouseValve) return;
	mouseValve = false;
	setTimeout(() => (mouseValve = true), dur);
	if (e.wheelDelta < 0) {
		next();
	} else {
		prev();
	}
};

};